package com.health.db.dao.msg.impl;

import java.util.List;

import com.health.db.dao.ServiceInterface;
import com.health.db.dao.msg.IImMsgNoticeDao;
import com.health.db.mapper.ImMsgNoticeMapper;
import com.health.db.model.ImMsgNotice;
import com.health.db.model.ImMsgNoticeExample;
import com.health.db.model.RegisterOrder;
import com.health.redis.RedisConstants;


public class ImMsgNoticeDaoImpl0908 extends ServiceInterface implements IImMsgNoticeDao {

    private ImMsgNoticeMapper imMsgNoticeMapper;

    private String  selectByNoticeReceiveAddress=":noticeReceiveAddress:";
    private String  selectByIsUsedFlag=":isUsedFlag:";
	@Override
	public int insert(ImMsgNoticeExample record) {
		
		int result=-1;
		getRedisOperatiorLogic();
		 
		String key=RedisConstants.ImMsgNoticeMapper+selectByNoticeReceiveAddress+record.getNoticeReceiveAddress()
				+selectByIsUsedFlag+record.getIsUsedFlag();
		
		List<ImMsgNotice>  imMsgNoticeList =null;
		 Object object=null;
	
		 imMsgNoticeList.add(record);
			
		 result= imMsgNoticeMapper.insert(record);
				 
		if(redisOperatiorLogic.isJedisIsConnected())
		{
					//5 min
			redisOperatiorLogic.setEx(key, 5*60,imMsgNoticeList, getOrderRedisGroupNo("1"));
		}
		
		// TODO Auto-generated method stub
		return result;
	}

	@Override
	public List<ImMsgNotice> selectByExample(ImMsgNoticeExample example) {
		// TODO Auto-generated method stub
		
		getRedisOperatiorLogic();
		 
		String key=RedisConstants.ImMsgNoticeMapper+selectByNoticeReceiveAddress+example.getNoticeReceiveAddress()
				+selectByIsUsedFlag+example.getIsUsedFlag();
		
		List<ImMsgNotice>  imMsgNoticeList =null;
		 Object object=null;
		 
		if(redisOperatiorLogic.isJedisIsConnected())
		{
			
			object=redisOperatiorLogic.readObject(key, getOrderRedisGroupNo("1"));
			
		}
		
		if(null!=object && !"".equals(object))
		{
			imMsgNoticeList=(List<ImMsgNotice>) object;
		}
		else
		{
			imMsgNoticeList  = imMsgNoticeMapper.selectByExample(example);
			
			if(redisOperatiorLogic.isJedisIsConnected())
			{
				
				redisOperatiorLogic.setEx(key, imMsgNoticeList, getOrderRedisGroupNo("1"));
			}
		}

		
		return imMsgNoticeList;
	}

	@Override
	public int updateByPrimaryKeySelective(ImMsgNotice record) {
		// TODO Auto-generated method stub
		return imMsgNoticeMapper.updateByPrimaryKeySelective(record);
	}

	/**
	 * @return the imMsgNoticeMapper
	 */
	public ImMsgNoticeMapper getImMsgNoticeMapper() {
		return imMsgNoticeMapper;
	}

	/**
	 * @param imMsgNoticeMapper the imMsgNoticeMapper to set
	 */
	public void setImMsgNoticeMapper(ImMsgNoticeMapper imMsgNoticeMapper) {
		this.imMsgNoticeMapper = imMsgNoticeMapper;
	}

	@Override
	public int updateForUserd(ImMsgNotice record) {
		// TODO Auto-generated method stub
		
		int result=-1;
		getRedisOperatiorLogic();
		 
		String key=RedisConstants.ImMsgNoticeMapper+selectByNoticeReceiveAddress+record.getNoticeReceiveAddress()
				+selectByIsUsedFlag+record.getIsUsedFlag();
		
		List<ImMsgNotice>  imMsgNoticeList =null;
		 Object object=null;
	
		result= imMsgNoticeMapper.updateForUserd(record);
				 
		if(redisOperatiorLogic.isJedisIsConnected())
		{
					//5 min
			redisOperatiorLogic.setEx(key, 5*60,record, getOrderRedisGroupNo("1"));
		}
		// TODO Auto-generated method stub
		return result;
	 
	}

	@Override
	public int countNotice(ImMsgNoticeExample example) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public boolean checkNotice(ImMsgNoticeExample example) {
		// TODO Auto-generated method stub
		return false;
	}

	
 
}
